import request from '@/utils/request'
import { ObjToQueryString } from '@/utils/method'
const baseUrl = process.env.VUE_APP_BASE_API

// 财务数据
export const getFinanceCurrent = (params) => {
  return request({
    url: '/statics/finance/current',
    params,
    method: 'get'
  })
}
export const getFinanceHistory = (params) => {
  return request({
    url: '/statics/finance/history',
    params,
    method: 'get'
  })
}
// 放款记录
export const getLoanRecord = (params) => {
  return request({
    url: '/finance/payment/loan/list',
    params,
    method: 'get'
  })
}
export const exportLoanRecord = (params) => {
  const url = 'finance/payment/loan/list/export'
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
// 还款记录
export const getRepaymentRecord = (params) => {
  return request({
    url: '/finance/repayment/repaymentRecord',
    params,
    method: 'get'
  })
}
export const exportRepaymentRecord = (params) => {
  const url = '/finance/repayment/repaymentRecord/export'
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
// 支付平台账户监测
export const getAccountMonitoring = (params) => {
  return request({
    url: '/accountDetection',
    params,
    method: 'get'
  })
}
export const updateAccountMonitoring = (data) => {
  return request({
    url: '/accountDetection',
    data,
    method: 'put'
  })
}
export const exportAccountMonitoring = (params) => {
  const url = '/accountDetection/export'
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
// 还款告知
export const getRepayProofs = (params) => {
  return request({
    url: '/repayProofs',
    params,
    method: 'get'
  })
}
export const updateRepayProof = (data) => {
  return request({
    url: '/repayProof/update',
    data,
    method: 'put'
  })
}
export const getThisRepaymentNotice = (id) => {
  return request({
    url: `/repayProof/${id}`,
    method: 'get'
  })
}
export const simpleInfo = (id) => {
  return request({
    url: `/user/simpleInfo/${id}`,
    method: 'get'
  })
}
// 放款管理
export const queryPayment = (params) => {
  return request({
    url: '/finance/payment/queryPayment',
    params,
    method: 'get'
  })
}
export const queryPaymentExport = (params) => {
  const url = '/finance/payment/queryPaymentExport'
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
// 放款审核
export const paymentAgain = (data) => {
  return request({
    url: '/finance/payment/again',
    data,
    method: 'put'
  })
}
export const confirmLoan = (data) => {
  return request({
    url: '/finance/payment/confirmLoan',
    data,
    method: 'patch'
  })
}
// 还款管理
export const queryRepaymentManage = (params) => {
  return request({
    url: '/finance/repayment/queryRepaymentManage',
    params,
    method: 'get'
  })
}
export const financeRepayment = (data) => {
  return request({
    url: '/finance/repayment',
    data,
    method: 'patch'
  })
}
export const paymentLoanList = (params) => {
  return request({
    url: '/finance/payment/loan/list',
    params,
    method: 'get'
  })
}
export const manualRepaymentList = (orderId, params) => {
  return request({
    url: `/finance/repayment/manualRepaymentList/${orderId}`,
    params,
    method: 'get'
  })
}
export const paymentLoanListExport = (params) => {
  const url = '/finance/payment/loan/list/export'
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
export const queryRepaymentManageExport = (params) => {
  const url = '/finance/repayment/queryRepaymentManageExport'
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
